/**
 * Created by XGJ on 2017/9/21.
 */

import {Component} from "@angular/core";
import {HttpService} from "../../../providers/HttpService";
import {NativeServiceC} from "../../../providers/NativeServiceC";
import {NavController} from "ionic-angular";
import {ClassifyDetailPage} from "../classifyDetailPage/classifyDetail";

@Component({
    selector: 'page-classify',
    templateUrl: 'classify.html'
})


export class ClassifyPage{

    collections=[];
    Style=[];
    Class=[];

    constructor(public navCtrl: NavController,
                private httpService:HttpService,
                private nativeService:NativeServiceC,
    ){}

    ionViewDidLoad() {
        this.getCollections();
        this.getStyles();
    }

    private getCollections(){
        let url = '/v1/collections',
            sender = {
                limit: 6,
                offset: 0,
            };
        this.httpService.get(url,sender).subscribe(res =>{
            console.log(res);
            this.collections = res.collections;
            this.nativeService.hideLoading();
        })
    }

    private getStyles(){
        let url = '/v1/channel_groups/all';
        this.httpService.get(url).subscribe(res =>{
            console.log(res);
            this.Style = res.channel_groups[0];
            this.Class = res.channel_groups[1];
            this.nativeService.hideLoading();
        })
    }

    private pushController(sender:Object){
        this.navCtrl.push(ClassifyDetailPage,sender);
    }

    //跳转
    allClassify(collection){
        collection = collection || {};
        let sender={
            title : collection['title'] || "全部分类",
            id :collection['id'] || 0,
            type:'collections'
        };
        this.pushController(sender);
    }

    classifyClick(style){
        style = style||{};
        let sender = {
            title : style['name'],
            id :style['id']||0,
            type:'style'
        };
        this.pushController(sender);
    }
}